package com.oyjd.framework.util.del;

import java.io.File;

import android.os.Environment;
import android.util.Log;

/**
 * 删除sdcard目录
 * 
 * @author 欧建东
 * @email oyjd@163.com
 * 
 */
public class DelFolder {
	private static final String TAG = "DelFolder";

	/**
	 * 删除图片库
	 * 
	 * @param activity
	 */
	public static void del(String folderPath) {
		if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
			File sdCardDir = Environment.getExternalStorageDirectory();// 获取SDCard目录
			File f = new File(sdCardDir + folderPath);
			try {
				delFolder(f);
				Log.i(TAG, "删除sdcard目录成功！--->" + sdCardDir + folderPath);
			} catch (Exception err) {
				Log.i(TAG, "删除sdcard目录失败！--->" + sdCardDir + folderPath, err);
			}
		} else {
			Log.i(TAG, "sdcard不存在！");
		}

	}

	/**
	 * 迭代删除文件或文件夹
	 * 
	 * @param f
	 */
	private static void delFolder(File f) {
		if (f.exists()) {
			for (File file : f.listFiles()) {
				if (file.isDirectory()) {
					delFolder(file);
					file.delete();
				} else if (file.isFile()) {
					file.delete();
				}
			}
		}
	}
}
